#ifndef KEY_SWITCH_H
#define KEY_SWITCH_H

#include "context.h"
#include "ring_basis_extension.h"
#include "ring_poly.h"
#include "keygen.h"
/* *
 * @class KeySwitcher
 * @brief 密钥切换器类，用于在同态加密中切换密钥。
 *
 * `KeySwitcher` 类提供了密钥切换相关的操作，如密钥切换、基扩展、分解等，用于实现同态加密中的密钥管理。
 */
class KeySwitcher {
public:
    Context *params;
    std::vector<PolyQP *> pool;
    std::vector<PolyQP *> poolTest0;
    std::vector<PolyQP *> poolTest1;
    std::vector<Poly *> poolQ;
    Poly *poolInvNTT;
    std::vector<PolyQP *> poolDecompQP; // Memory pool for the basis extension in hoisting
    FastBasisExtender *baseconverter;
    Decomposer *decomposer;

    KeySwitcher(Context *params);
    // 拷贝构造函数
    KeySwitcher(const KeySwitcher &) = delete;
    KeySwitcher &operator = (const KeySwitcher &) = delete;
    // 移动构造函数
    KeySwitcher(KeySwitcher &&other) = delete;
    KeySwitcher &operator = (KeySwitcher &&other) = delete;

    void SwitchKeysInPlace(int levelQ, Poly *cx, SwitchingKey *evakey, Poly *p0, Poly *p1);
    void SwitchKeysInPlaceNoModDown(int levelQ, Poly *cx, SwitchingKey *evakey, Poly *c0Q, Poly *c0P, Poly *c1Q,
        Poly *c1P);
    void DecomposeSingleNTT(int levelQ, int levelP, int alpha, int beta, Poly *c2NTT, Poly *c2InvNTT, Poly *c2QiQ,
        Poly *c2QiP);
};

#endif